#ifndef MESSAGEPARSER_H
#define MESSAGEPARSER_H

#include "abstractparser.h"


class AbstractEvent;
class MessageParser : public AbstractParser
{
    Q_OBJECT
public:
    explicit MessageParser(QObject *parent = 0);

public:
    virtual AbstractParser::Type type() const;
    virtual AbstractEvent *parse(const QString &commandId, const QVariant &data);

private:
    AbstractEvent *parseMessage(const QVariant &data);
    AbstractEvent *parseMessageFromWeb(const QVariant &data);
    AbstractEvent *parseMessageGroup(const QVariant &data);

    bool parseStringFieldOfMap(const QVariantMap &map,
                               const QString &field,
                               QVariant &fieldValue);

    bool parseIntFieldOfMap(const QVariantMap &map,
                            const QString &field,
                            QVariant &fieldValue);

    bool parseMessageMap(const QVariantMap &map,
                         qint64 &id,
                         qint64 &idt,
                         qint64 &chid,
                         qint64 &from,
                         qint64 &to,
                         qint64 &tcreate,
                         QString &msg);
};

#endif // MESSAGEPARSER_H
